﻿Public Class FrmThangNam
    'Public Delegate Sub Fill()
    'Public Shadows Refresh As Fill

    Private _LaQuy As Boolean = False
    Public LaThoat As Boolean
    Public Property LaQuy() As Boolean
        Get
            Return _LaQuy
        End Get
        Set(ByVal value As Boolean)
            _LaQuy = value
        End Set
    End Property

    Private _thang As Integer
    Public Property thang() As Integer
        Get
            Return _thang
        End Get
        Set(ByVal value As Integer)
            _thang = value
        End Set
    End Property
    Private _nam As Integer
    Public Property nam() As Integer
        Get
            Return _nam
        End Get
        Set(ByVal value As Integer)
            _nam = value
        End Set
    End Property

    Private _NgayMax As Date? = Nothing
    Public Property NgayMax() As Date?
        Get
            Return _NgayMax
        End Get
        Set(ByVal value As Date?)
            _NgayMax = value
        End Set
    End Property

    Private _LaChonThoiGianHT As Boolean
    Public Property LaConThoiGianHT() As Boolean
        Get
            Return _LaChonThoiGianHT
        End Get
        Set(ByVal value As Boolean)
            _LaChonThoiGianHT = value
        End Set
    End Property


    Private Sub FrmThangNam_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If (e.Modifiers = GetKeyModifide("EXIT") And _
     e.KeyCode = GetKeyCode2("EXIT")) Or _
     (e.KeyCode = GetKeyCode("EXIT")) Then
            btnThoat_Click(Nothing, Nothing)
        End If


        If (e.Modifiers = GetKeyModifide("ACCEPT") And _
     e.KeyCode = GetKeyCode2("ACCEPT")) Or _
     (e.KeyCode = GetKeyCode("ACCEPT")) Then

            If btnChapNhan.Enabled = True And btnChapNhan.Visible = True Then
                btnChapNhan_Click(Nothing, Nothing)
            End If

        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If vIntKTNam = 0 Or vIntKTThang = 0 Then
            spnNamLamViec.EditValue = dbTV.GetDateTimeServer.Value.Year
            spnThangLamViec.EditValue = dbTV.GetDateTimeServer.Value.Month
        Else
            spnNamLamViec.EditValue = vIntKTNam
            spnThangLamViec.EditValue = vIntKTThang
        End If
        
        spnNamLamViec.SelectAll()
        spnThangLamViec.SelectAll()
        btnThoat.Text = BtnCancelCaption
        btnChapNhan.Text = BtnAcceptCaption
    End Sub

    Private Sub btnChapNhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChapNhan.Click
        If NgayMax IsNot Nothing Then
            If spnThangLamViec.Value <> 0 And spnNamLamViec.Value <> 0 Then
                Dim dtCheck = New DateTime(spnNamLamViec.Value, spnThangLamViec.Value, 1)
                If dtCheck > NgayMax Then
                    MsgErr("Thời gian chọn không hợp lệ do đang làm hóa đơn hoàn trả tháng " & NgayMax.Value.Month & " năm " & NgayMax.Value.Year & "!")
                    Return
                End If
            End If
        End If

        If LaConThoiGianHT Then
            nam = spnNamLamViec.Value
            thang = spnThangLamViec.Value
            vIntKTNam = spnNamLamViec.EditValue
            vIntKTThang = spnThangLamViec.EditValue
            If nam < 0 Then nam = dbTV.GetDateTimeServer.Value.Year
            If thang < 0 Then thang = dbTV.GetDateTimeServer.Value.Month
            Close()
        Else
            nam = spnNamLamViec.Value
            thang = spnThangLamViec.Value
            spnNamLamViec.EditValue = vIntKTNam
            spnThangLamViec.EditValue = vIntKTThang
            If nam < 0 Then nam = dbTV.GetDateTimeServer.Value.Year
            If thang < 0 Then thang = dbTV.GetDateTimeServer.Value.Month
            Me.Close()
        End If
    End Sub


    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        nam = 0
        thang = 0
        LaThoat = True
        Me.Close()
    End Sub
End Class